﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.Security;

namespace Recetas_Web
{
    public partial class Login : System.Web.UI.Page
    {


        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Main"].ConnectionString);
            cn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = cn;
            cmd.CommandText = "loginuser";
            cmd.Parameters.Add("@user", SqlDbType.VarChar).Value = TextBox1.Text;
            cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = TextBox2.Text;
            int usercount = (Int32)cmd.ExecuteScalar();
            if (usercount == 1)  // si encuentra 1 registro
            {

                Session["Name"] = TextBox1.Text;
                FormsAuthentication.SetAuthCookie(TextBox1.Text, false);
                Response.Redirect("Principal.aspx");  //Sesion exitosa
            }
            else
            {
                
                cn.Close();
                Label3.Visible = true;

            }
        }

        protected void lbRegistrarse_Click(object sender, EventArgs e)
        {
            Server.Transfer("Registrar_Usuarios.aspx");
        }
    }
}